﻿@model IEnumerable<WebUI.Models.SiteCfg>
@{
    ViewBag.Title = "系统设置";
    var hours = new string[24];
    for (int i = 0; i < 24; i++)
    {
        hours[i] = i.ToString();
    }
}
@helper RenderCfgForm(bool SkipOnSuccessScript, Func<dynamic, object> template)
    {
    using (Ajax.BeginForm(new AjaxOptions()
    {
        LoadingElementId = "OnLoadingSpan",
        UpdateTargetId = "dialogbox",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "Post",
        OnSuccess = SkipOnSuccessScript ? "" : "$('#dialogbox').dialog('close');",
        OnFailure = "OnSiteError"
    }))
    {
    @Html.ValidationSummary(true)
    @template(null)
    }
}
<table class="whidth noboard">
<tr><td colspan="2">系统版本：@SiteAssemblyVersion</td></tr>
    <tr>
        <td>
            @RenderCfgForm(false,
                @<fieldset>
                    @{var m = Model.FirstOrDefault(v => v.ID == "SmsSentHour");}
                    <legend>@Html.Label(m.Title)</legend>
                    @Html.Hidden("ID", m.ID)
                    <div class="editor-field">
                        @Html.Label(m.Title): 每天 @Html.DropDownList("Value", new SelectList(hours, m.Value))
                        点
                    </div>
                    <div>
                        下次随访发送时间：@ViewBag.SmsNextSendTime
                        <br />
                        下次短信处理时间：@ViewBag.SmsNextReadTime
                    </div>
                    @Helpers.SubmitButton("保存", "Act")
                </fieldset>
            )
        </td>
        <td>
            @RenderCfgForm(false,
                @<fieldset>
                    <legend>短信随访错误提示</legend>
                    @{var m = Model.FirstOrDefault(v => v.ID == "errorMessage");}
                    @Html.Hidden("ID", m.ID)
                    <div class="editor-field">
                        @Html.TextArea("Value", m.Value, 2, 30, null)
                    </div>
                    <div class="error">
                        @Helpers.SubmitButton("保存", "Act")
                        <span id="smsTextCount"></span>
                    </div>
                </fieldset>
            )
        </td>
    </tr>
    <tr>
        <td>
            @RenderCfgForm(true,
                @<fieldset>
                    <legend>管理员短信服务测试</legend>
                    <div>
                        模拟日期：<input type="text" name="MockNow" value="@(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))" /><br />
                        测试患者：<input type="text" name="MockUsers" value="用户1,用户2" /><br />
                    </div>
                    <div class="error">
                        @Helpers.SubmitButton("执行测试", "Act")
                    </div>
                </fieldset>
            )
        </td>
        <td>
            @RenderCfgForm(true,
                @<fieldset>
                    <legend>管理员模拟短信回复</legend>
                    <div>
                        手机号：<input type="text" name="MockSenderCode" value="11111111111" /><br />
                        回复内容：<input type="text" name="MockSmsText" value="0" /><br />
                    </div>
                    <div class="error">
                        @Helpers.SubmitButton("回复短信", "Act")
                    </div>
                </fieldset>
            )
        </td>
    </tr>
</table>
@if (!string.IsNullOrEmpty(ViewBag.DebugLog))
{
    <textarea cols="80">@ViewBag.DebugLog</textarea>
}
<script type="text/javascript">
    $(document).ready(function () {
        var text = $("#errorMessage").val();
        if (!text) text = "";
        var counter = text.length;
        if (counter != 0) {
            $("#smsTextCount").text("字数：" + counter.toString());
        }
        else {
            $("#smsTextCount").text("");
        }
        $("#errorMessage").keyup(function () {
            var text = $("#errorMessage").val();
            var counter = text.length;
            if (counter != 0) {
                $("#smsTextCount").text("字数：" + counter.toString());
            }
            else {
                $("#smsTextCount").text("");
            }
        });
    });

</script>
